﻿function TodoController($scope, $http) {
    var vm = this;

    vm.todoItems = [];
    vm.errorMessage = '';

    vm.getTodos = function () {
        $http({
            url: '/api/Todo/',
            method: 'GET'
        }).success(function (data) {
            for (var t in data) {
                vm.todoItems.push(data[t]);
            }

            vm.errorMessage = '';
        }).error(function () {
            vm.errorMessage = "Sorry, some error occured or you're not authorized to eat peanut butter.";
        });
    };

    vm.getTodos();
}

TodoController.$inject = ['$scope', '$http'];